package com.dusk.tool
{
    import flash.utils.ByteArray;
    
    public class SwfParser
    {
        
        private var _swfByteArray:ByteArray = new ByteArray();
        private var _swfSize:int;
        private var _frameRate:int;
        private var _frameTotal:int;
        private var _version:int;
        private var _classList:Array;
        
        public function parseSwf(_arg_1:ByteArray):void
        {
            var _local_3:* = _arg_1;
            var _local_4:String = _local_3.readUTFBytes(3);
            _version = _local_3.readByte();
            var _local_5:uint = _local_3.readUnsignedInt();
            _local_3.position = 8;
            _local_3.readBytes(_swfByteArray);
            if (_local_4 == "CWS")
            {
                _swfByteArray.uncompress();
            }
            _swfByteArray.endian = "littleEndian";
            _swfSize = _swfByteArray.readUnsignedByte() >> 3;
            _swfByteArray.position = Math.ceil((_swfSize * 4) / 8 + 5);
            _frameRate = _swfByteArray.readShort() / 0x0100;
            _frameTotal = _swfByteArray.readShort();
        }
        
        public function getSymbolClassLink():Array
        {
            var _local_3:int;
            var _local_2:int;
            var _local_1:int;
            _swfByteArray.endian = "littleEndian";
            while (_swfByteArray.bytesAvailable)
            {
                _local_3 = _swfByteArray.readShort();
                _local_2 = _local_3 >> 6;
                _local_1 = _local_3 & 0x3F;
                if (_local_1 == 63)
                {
                    _local_1 = _swfByteArray.readUnsignedInt();
                }
                if (_local_2 == 76)
                {
                    _classList = [];
                    try
                    {
                        parseSymbolClass(_local_1);
                    } catch (error:Error)
                    {
                        throw new Error("素材解析出错");
                    }
                }
                else
                {
                    _swfByteArray.position = _swfByteArray.position + _local_1;
                }
            }
            return _classList;
        }
        
        private function parseSymbolClass(_arg_1:int):void
        {
            var _local_3:int;
            var _local_2:int;
            var _local_4:* = null;
            var _local_5:int = _swfByteArray.readShort();
            while (_local_5--)
            {
                _local_3 = _swfByteArray.readUnsignedShort();
                _local_2 = _swfByteArray.readByte();
                _local_4 = "";
                while (_local_2)
                {
                    _local_4 = _local_4 + String.fromCharCode(_local_2);
                    _local_2 = _swfByteArray.readByte();
                }
                _classList.push(_local_4);
            }
        }
    }
}

